//新增Input的html,每行放两条数据，flag 0表示是左列的，1表示是右列的,2表示一行只有一条数据,readflag 是否只读
function addInput(id, text, flag, readflag) {
    var html = '';
    if (flag == 0 | flag == 2) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var value = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
        }
    }
    var readonly = "";
    if (readflag)
        readonly = "readonly";
    html += '<input type="text" class="form-control" name="' + id + '" id="' + id + '" value="' + value + '" ' + readonly + '>';

    html += '</div>';
    if (flag == 1 | flag == 2) {
        html += '</div>';
    }
    return html;
}
function addInputText(id, text, flag, readflag) {
    var html = '';
    if (flag == 0 | flag == 2) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var value = "", value_text = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
            value_text = modifyData[id + "_text"];
        }
    }
    var readonly = "";
    if (readflag)
        readonly = "readonly";
    html += '<input type="text" class="form-control" name="' + id + '_text" id="' + id + '_text" value="' + value_text + '" ' + readonly + '>';
    html += '<input type="text" style="display: none" class="form-control" name="' + id + '" id="' + id + '" value="' + value + '" ' + readonly + '>';

    html += '</div>';
    if (flag == 1 | flag == 2) {
        html += '</div>';
    }
    return html;
}

function addInput_clear(id, text, flag, readflag) {
    var html = '';
    if (flag == 0 | flag == 2) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var value = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
        }
    }
    var readonly = "";
    if (readflag)
        readonly = "readonly";
    html += '<input type="text" class="form-control" name="' + id + '" id="' + id + '" value="' + value + '" ' + readonly + '>';
    html += '</div>';
    if (flag == 1 | flag == 2) {
        html += '</div>';
    }
    return html;
}
function addSelectTree(id, text, flag, selecttreefuncname, readonlyflag) {
    var html = '';
    if (flag != 1) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var value_text = '';
    var value = '';
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value_text = modifyData[id + "_text"];
            value = modifyData[id];
        }
    }
    html += '<input type="text" class="form-control" id="' + id + '_text" name="' + id + '_text" readonly value="' + value_text + '">';
    html += '<input type="text" style="display: none" class="form-control" id="' + id + '" name="' + id + '" value="' + value + '">';
    if (!readonlyflag)
        html += '<a onclick="' + selecttreefuncname + '()" href=#>选择' + text + '</a>';

    html += '</div>';
    if (flag != 0) {
        html += '</div>';
    }
    return html;
}

//新增基表类型下拉框的html,每行放两条数据，flag 0表示是左列的，1表示是右列的，tableName是基表名称
function addSelect(id, text, flag, tableName, readflag) {
    if (readflag) {
        return addInputText(id, text, flag, readflag);
    }

    var html = '';
    if (flag != 1) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var value = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
        }
    }
    var readonly = "";
    if (readflag)
        readonly = 'readonly="readonly"';
    html += '<select id="' + id + '" name="' + id + '" class="form-control" ' + readonly + '>';
    var result = ajaxResult('GET', false, '/cnmuseum/MbXtglBaseTableServlet.getPullData.do', {tn: tableName});
    if (result.status == 'OK') {
        var data = result.rows;
        html += '<option value="">请选择</option>';
        for (var i = 0; i < data.length; i++) {
            if (modifyData != null) {
                if (data[i].id == modifyData[id]) {
                    html += '<option value="' + data[i].id + '" selected="selected">' + data[i].name + '</option>';
                } else {
                    html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                }
            } else {
                html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
            }

        }
    }

    html += '</select>';
    html += '</div>';
    if (flag != 0) {
        html += '</div>';
    }
    return html;
}


//新增基表类型下拉框的html,每行放两条数据，flag 0表示是左列的，1表示是右列的，tableName是基表名称
function addSelect_MultipleLevel(id, text, flag, tableName, maxLevel, readflag) {
    var html = '';
    if (flag != 1) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-6">';
    var perwidth = 100 / maxLevel;
    for (var i = 1; i <= maxLevel; i++) {
        if (!readflag)
            html += '<select id="' + id + '_' + i + '" name="' + id + '_' + i + '" class="form-control" style="width:' + perwidth + '%"></select>';
        else
            html += '<input readonly id="' + id + '_' + i + '" name="' + id + '_' + i + '" class="form-control" style="width:' + perwidth + '%">';
    }

    var value = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
        }
    }
    html += '<input type=hidden id="' + id + '" name="' + id + '" value="' + value + '">';
    html += '</div>';
    if (flag != 0) {
        html += '</div>';
    }
    return html;
}
//给多级select赋值
function setSelect_MultipleLevel(id, tableName, readflag) {
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            var url = "MbXtglBaseTableServlet.getParentDataByid.do";
            var data = ajaxResult("post", false, url, {"tn": tableName, "id": modifyData[id]});
            if (data.status == "OK") {
                $.each(data.rows, function (index, item) {
                    if (readflag) {
                        $("#" + id + "_" + (index + 1)).val(item.name);
                    } else {
                        $("#" + id + "_" + (index + 1)).val(item.id);
                        $("#" + id + "_" + (index + 1)).change();
                    }
                });
            }
        }
    }

}
//新增特殊基表,colName是显示的名称，即option中text值对应显示的内容在数据库表的字段名称
function addSelectSpecial_nd(id, text, flag, tableName, colName, readflag) {
    if (readflag)
        return addInputText(id, text, flag, readflag);
    var html = '';
    if (flag == 0 | flag == 2) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-4">';
    var readonly = "";
    if (readflag)
        readonly = "readonly";
    html += '<select id="' + id + '" name="' + id + '" class="form-control" ' + readonly + '>';
    var val = '';
    if (modifyData != null) {
        val = modifyData[id];
    }

    var result = ajaxResult('GET', false, 'MbXtglBaseTableServlet.getPullNdData4select.do', {tn: tableName});
    if (result.status == 'OK') {
        var data = result.rows;
        html += '<option value="">请选择</option>';
        for (var i = 0; i < data.length; i++) {
            if (val == data[i].id)
                html += '<option value="' + data[i].id + '" selected>' + data[i][colName] + '</option>';
            else
                html += '<option value="' + data[i].id + '">' + data[i][colName] + '</option>';
        }
    }

    html += '</select>';
    html += '</div>';
    if (flag == 1 | flag == 2) {
        html += '</div>';
    }
    return html;
}
function objInit(obj) {
    $(obj).html('<option value=\'\'>请选择</option>')
}
// 加载多级数据内容
function selectMult(url, domid, tablename, parentid, level, maxLevel) {
    var data = ajaxResult("post", false, url, {"tn": tablename, "parentid": parentid});
    var did = domid + "_" + level;
    var selectDom = document.getElementById(did);
    //selectDom.options.add(new Option('请选择',''));
    $(selectDom).html('<option value=\'\'>请选择</option>')
    if (data.status == "OK") {
        $.each(data.rows, function (index, item) {
            selectDom.options.add(new Option(item.name, item.id));
        });
        $("#" + did).change(function () {
            var optionId = $("#" + did + " option:selected").val();
            if (optionId != "") {
                if (level < maxLevel) {
                    for (var i = level + 1; i <= maxLevel; i++) {
                        objInit($("#" + domid + "_" + i));
                    }
                    selectMult(url, domid, tablename, optionId, level + 1, maxLevel);
                }
                $("#" + domid).val(optionId);
            }
        });
    }
    else
        alertFunc("数据加载失败");

}

//从用户上传的文件列表里选择资源,flag 1上传影像资源，2上传音频，3视频，4三维模型，5文献，打开的modal不同
function addResource(id, text, flag, readflag) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-5">';
    if (modifyData != null) {
        html += '<input type="text" class="form-control" name="' + id + '1" id="' + id + '1" value="' + modifyData[id] + '">';
    } else {
        html += '<input type="text" class="form-control" name="' + id + '1" id="' + id + '1">';
    }
    html += '</div>';
    if (!readflag) {
        html += '<div class="col-md-2">';
        id = id.replace(/\"/g, "'");
        html += '<button type="button" class="btn btn-primary"  onclick="chooseResource(\'' + id + '\',' + flag + ');">选择资源</button>';
        html += '<input name=' + id + ' id=' + id + ' type="hidden">';
        html += '</div>';
    }
    html += '</div>';
    return html;
}
//从用户上传的文件列表里选择资源,flag 1上传影像资源，2上传音频，3视频，4三维模型，5文献，打开的modal不同
function addResource2(id, text, flag, readflag) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-7">';
    var val = '', val1 = '';

    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id + "1"] != '' & modifyData[id + "1"] != undefined) {
            val = modifyData[id];
            val1 = modifyData[id + "1"];
        }
    }

    html += '<input type="text" readonly class="form-control" name="' + id + '1" id="' + id + '1" value="' + val1 + '">';
    html += '<input name=' + id + ' id=' + id + ' type="hidden" value="' + val + '">';
    html += '</div>';

    var val = modifyData[id];

    if (!readflag) {
        html += '<div class="col-md-2">';
        id = id.replace(/\"/g, "'");
        html += '<button type="button" class="btn btn-primary"  onclick="chooseResource(\'' + id + '\',' + flag + ');">选择资源</button>&nbsp;';
        html += '<button type="button" class="btn btn-primary"  onclick="importResource(\'' + id + '\',' + flag + ');">上传资源</button>';

        html += '</div>';
    }
    html += '</div>';
    return html;
}
//新增日期选择的html,每行放两条数据，flag 0表示是左列的，1表示是右列的,2表示一行只有一条数据
function addTime(id, text, flag, readflag) {
    var html = '';
    if (flag == 0) {
        html += '<div class="row">';
    }
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="input-group date form_date1 col-md-4" style="float:left;padding-left:15px;padding-right:15px;margin-left:0;margin-right:0;" data-date="" data-date-format="yyyy-MM-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">';
    html += '<input class="form-control" size="12" type="text" value="" readonly id="' + id + '" name="' + id + '">';
    html += '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>';
    html += '</div>';
    if (flag == 1) {
        html += '</div>';
    }
    return html;
}

//获取advice textarea的html，每行只放一条
function addTextarea(id, text, readflag) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-6">';

    var value = "";
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            value = modifyData[id];
        }
    }
    var readonly = "";
    if (readflag)
        readonly = "readonly";
    html += '<textarea class="form-control" id="' + id + '" name="' + id + '" rows="3" ' + readonly + '>' + value + '</textarea>';

    html += '</div>';
    html += '</div>';
    return html;
}
//获取textarea的html，每行只放一条
function addAdviceTextarea(id, text, readflag) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-6">';
    var val = '';
    if (modifyData != null & modifyData != undefined) {
        if (modifyData[id] != '' & modifyData[id] != undefined) {
            val = modifyData[id];
        }
    }
    var readonly = "";
//	if(readflag)
//		readonly = "readonly";
    html += '<textarea class="form-control" id="' + id + '" name="' + id + '" rows="3" ' + readonly + '>' + val + '</textarea>';
    html += '</div>';
    html += '</div>';
    return html;
}

//新增上传文件的Html，flag 1表示多文件上传，flag 0表示多文件上传
function addFileput(id, text, flag) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>';
    html += '</div>';
    html += '<div class="col-md-8">';
    if (flag == 0) {
        html += '<div class="file-loading"><input id="' + id + '" name="' + id + '" type="file"></div>';
    } else {
        html += '<div class="file-loading"><input id="' + id + '" name="' + id + '" type="file" multiple></div>';
    }
    html += '</div>';
    html += '</div>';
    return html;
}
//时间范围html
function add2Time(id1, id2, text) {
    var html = '';
    html += '<div class="row">';
    html += '<div class="col-md-2 text-right">';
    html += '<span>' + text + '：</span>	';
    html += '</div>';
    html += '<div class="input-group date form_date1 col-md-3" style="float:left;" data-date="" data-date-format="yyyy-MM-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">';
    html += '<input class="form-control" size="16" type="text" value="" readonly id="' + id1 + '">';
    html += '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>';
    html += '</div>';
    html += '<span style="float:left;">至</span>';
    html += '<div class="input-group date form_date1 col-md-3" style="float:left;" data-date="" data-date-format="yyyy-MM-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">';
    html += '<input class="form-control" size="16" type="text" value="" readonly id="' + id2 + '">';
    html += '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>';
    html += '</div>';
    html += ' </div>';
    return html;
}
//多图片上传
function imgInput(selector, url) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: 'mbgyfileServlet.insert.do', //上传的地址
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: true, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //minImageWidth: 50, //图片的最小宽度
        //minImageHeight: 50,//图片的最小高度
        //maxImageWidth: 1000,//图片的最大宽度
        //maxImageHeight: 1000,//图片的最大高度
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        previewSettings: {
            image: {width: "50px", height: "50px"},
        },
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        previewFileIcon: "<iclass='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", function (event, data, previewId, index) {
        console.log(data);
    });
}
function audioInput(selector, url) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        allowedFileExtensions: ['mp3', 'wav', 'WAV'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", function (event, data, previewId, index) {

    });
}
function videoInput(selector, url) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        allowedFileExtensions: ['mp4', 'RMVB', 'rmvb'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", function (event, data, previewId, index) {

    });
}
function fileuploadInput(selector, url) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        //allowedFileExtensions: ['mp4', 'RMVB', 'rmvb'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", function (event, data, previewId, index) {

    });
}
//带返回函数上传文件
function imgInputByCallback(selector, url, callback) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: true, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //minImageWidth: 50, //图片的最小宽度
        //minImageHeight: 50,//图片的最小高度
        //maxImageWidth: 1000,//图片的最大宽度
        //maxImageHeight: 1000,//图片的最大高度
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        previewSettings: {
            image: {width: "50px", height: "50px"},
        },
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        previewFileIcon: "<iclass='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", callback);
}
function audioInputByCallback(selector, url, callback) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        allowedFileExtensions: ['mp3', 'wav', 'WAV'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", callback);
}
function videoInputByCallback(selector, url, callback) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        allowedFileExtensions: ['mp4', 'RMVB', 'rmvb'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", callback);
}
function fileuploadInputByCallback(selector, url, callback) {
    $(selector).fileinput({
        language: 'zh', //设置语言
        uploadUrl: url, //上传的地址
        //allowedFileExtensions: ['mp4', 'RMVB', 'rmvb'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showRemove: true, //显示移除按钮
        showPreview: false, //是否显示预览
        dropZoneEnabled: false,//是否显示拖拽区域
        //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
    }).on("fileuploaded", callback);
}